<%@include file="_header.jspf" %>
<%@page import="com.spartancoder.accommodation.models.AuthToken" %>
<%@page import="com.spartancoder.accommodation.models.Place" %>
<%@page import="com.spartancoder.accommodation.models.AccommodationSession" %>
<%@page import="com.spartancoder.accommodation.models.Options" %>
<%@page import="com.spartancoder.accommodation.beans.PlaceBean" %>
<%@page import="com.spartancoder.accommodation.beans.AccommodationSessionBean" %>
<%@page import="com.spartancoder.accommodation.beans.OptionBean" %>
<%
AuthToken authToken = (AuthToken)request.getAttribute("authToken");
AccommodationSessionBean as = AccommodationSession.fetchActive();

String pId = request.getParameter("pId");
String room = request.getParameter("room");
String comment = request.getParameter("comment");

if( pId != null && room != null && comment != null ) {
    OptionBean ob = new OptionBean();
    ob.setSessionId(as.getSessionId());
    ob.setStudentId(authToken.getId());
    ob.setPlaceId(Integer.parseInt(pId));
    ob.setStatusId(1);
    ob.setRoom(Integer.parseInt(room));
    ob.setComment(comment);
    Options.create(ob);
    
    session.setAttribute("flash", "Optiunea a fost salvata");
    response.sendRedirect("list-options.jsp");
}

%>

<h2>Adaugare optiune</h2>

<form action="add-options.jsp" method="post" class="span-10">
    <fieldset>

    <label class="text large">Camin:</label>
    <select name="pId" class="text large">
    <% for( PlaceBean pb : Place.fetchByCollege(authToken.getStudent().getCollegeId())) { %>
        <option value="<%=pb.getPlaceId()%>"><%=pb.getName()%></option>
    <% } %>
    </select><br />

    <label class="text large">Camera:</label><br />
    <input type="text" name="room" class="text large" /><br />

    <label class="text large">Comentariu:</label><br />
    <textarea name="comment" class="text large" style="height: 50px"></textarea><br />

    <button type="submit" class="positive button">Adauga</button>

    </fieldset>
</form>

<%@include file="_footer.jspf" %>